﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>btable</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/css/global.css" media="all">
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/css/btable.css" />
    <script src="/static/js/inout/jquery-1.8.2.min.js"></script>
</head>

<body>
<div style="margin: 15px;">
    <form id="fordes" method="post">
            <input type="hidden" name="roleid" value="{$roleid.id}"/>
        {volist name="authone" id="io"}
                <legend style="font-size: 15px;color: red;">{$io.title}&nbsp;&nbsp;<input type="checkbox" class="all" name="authid" value="{$io.id}" <?php if(in_array($io['id'],$rules)){echo 'checked';}?> /></legend>
                {volist name="io.children" id="is"}
                    <fieldset class="layui-elem-field site-demo-button lianke">
                        <legend style="font-size: 15px;color: red;">{$is.title}&nbsp;&nbsp;<input type="checkbox" class="all" name="authid" value="{$is.id}" <?php if(in_array($is['id'],$rules)){echo 'checked';}?> /></legend>
                            <div class="jkl">
                                {volist name="is.children" id="iv"}
                                    <div style="margin: 0;position: relative;display: inline-block;margin-left:5%;">
                                        <label class="layui-form-label" style="width: 100%;"><span>{$iv.title}</span>&nbsp;<input type="checkbox" name="authid" value="{$iv.id}" <?php if(in_array($iv['id'],$rules)){echo 'checked';}?>/></label>
                                    </div>
                                {/volist}
                            </div>
                    </fieldset>
                {/volist}
        {/volist}
            <div style="width:100%; height:50px;text-align: center;">
                <button type="button" id="bnt" class="layui-btn layui-btn-danger" onclick="tijiao();">提交</button>
                <button type="button" id="fanhui" class="layui-btn layui-btn-normal">返回</button>
            </div>
    </form>
</div>
<script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
<script>
    $(function(){
        $.fn.serializeJson=function(otherString){
            var serializeObj={},
                    array=this.serializeArray();
            $(array).each(function(){
                if(serializeObj[this.name]){
                    serializeObj[this.name]+=';'+this.value;
                }else{
                    serializeObj[this.name]=this.value;
                }
            });

            if(otherString!=undefined){
                var otherArray = otherString.split(';');
                $(otherArray).each(function(){
                    var otherSplitArray = this.split(':');
                    serializeObj[otherSplitArray[0]]=otherSplitArray[1];
                });
            }
            return serializeObj;
        };
        $(".all").click(function(){
            if(this.checked){
                $(this).parent().parent().find(".jkl :checkbox").prop("checked", true);
            }else{
                $(this).parent().parent().find(".jkl :checkbox").prop("checked", false);
            }
        });
        $("#fanhui").click(function(){
            window.history.go(-1);
        });
    });
    function tijiao(){
        var data = $('#fordes').serializeJson();
        $.post('/admin/role/allot',{data:data},function(res){
            if(res.status===0){
                layui.use(['layer', 'form'], function(){
                    layer.msg(res.msg);
                });
                setTimeout('window.location.href="/admin/role/index"',1000);
            }else{
                layui.use(['layer', 'form'], function(){
                    layer.msg(res.msg);
                });
            }
        });
    }
</script>
</body>
</html>